﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarchEstate.Manager.BusinesEntity;
using System.Collections;
using CoreFrame.Core.Orm;
using System.Data;
using CoreFrame.Business;
using Newtonsoft.Json;


public class PrintDebtformController : AbstractJqueryController
{
    #region 得到住宅欠费列表
    /// <summary>
    /// 得到住宅欠费列表
    /// </summary>
    public void GetHomeDebtList()
    {
        Hashtable hash = new Hashtable();

        int pagesize = Convert.ToInt32(ParamsData["page"]);
        int rows = Convert.ToInt32(ParamsData["rows"]);
        hash.Add("areacode", ParamsData["AreaCode"]);
        hash.Add("buildingCode", ParamsData["BuildingCode"]);
        hash.Add("roomname", ParamsData["RoomName"]);
       
        PageInfo page = new PageInfo(rows, pagesize);

        AbstractGenericModel model = NewObject<AbstractGenericModel>("debt");
        DataTable dtHomeList = (DataTable)model.OperationDataModel("GetHomeDebtList", hash, page);//住宅欠费数据

        string value = "";
        string child = "";
        List<OSrccItem> srccIdList = new List<OSrccItem>();
        for (int IntI = 0; IntI < dtHomeList.Rows.Count; IntI++)
        {
            string srccId=dtHomeList.Rows[IntI]["SrccId"].ToString();
            string ownername = dtHomeList.Rows[IntI]["OwnerName"].ToString();
            List<OSrccItem> findSrccidList = srccIdList.FindAll(x => x.SrccId == srccId);
            if (findSrccidList.Count!=0)
            {
                continue;
            }
            else
            {
                OSrccItem osrccItem = new OSrccItem();
                osrccItem.SrccId = srccId;
                osrccItem.OwnerName = ownername;
                value += "{\"id\":\"" + srccId + "\",\"OwnerName\":\"" + ownername + "\"},";
                srccIdList.Add(osrccItem);
            }
        }
        DataTable dtRow = dtHomeList.Clone();
         DataTable dtHomeCopy = dtHomeList.Copy();
        for (int IntI = 0; IntI < dtHomeCopy.Rows.Count; IntI++)
        {
            dtRow.Clear();
            dtRow.Rows.Add(dtHomeCopy.Rows[IntI].ItemArray);
            child = JavaScriptConvert.SerializeObject(dtRow);
                child = child.Substring(child.IndexOf("{") + 1);
                child = child.Remove(child.LastIndexOf("]"));
                value += "{\"id\":\"" + IntI + "\", \"_parentId\":\"" + dtHomeList.Rows[IntI]["SrccId"] + "\"," + child + ", ";
        }
        value = value.Remove(value.LastIndexOf(","));
        TxtJson = "{\"total\":" + page.totalRecord + ",\"rows\":[" + value + "]}";
    }
    #endregion

    #region 得到门面欠费列表
    /// <summary>
    /// 得到门面欠费列表
    /// </summary>
    public void GetShopDebtList()
    {
        Hashtable hash = new Hashtable();

        int pagesize = Convert.ToInt32(ParamsData["page"]);
        int rows = Convert.ToInt32(ParamsData["rows"]);
        hash.Add("shopname", ParamsData["ShopName"]);

        PageInfo page = new PageInfo(rows, pagesize);

        AbstractGenericModel model = NewObject<AbstractGenericModel>("debt");
        DataTable dtShopList = (DataTable)model.OperationDataModel("GetShopDebtList", hash, page);
        string value = "";
        string child = "";
        List<OSrccItem> srccIdList = new List<OSrccItem>();
        for (int IntI = 0; IntI < dtShopList.Rows.Count; IntI++)
        {
            string srccId = dtShopList.Rows[IntI]["SrccId"].ToString();
            string ownername = dtShopList.Rows[IntI]["OwnerName"].ToString();
            List<OSrccItem> findSrccidList = srccIdList.FindAll(x => x.SrccId == srccId);
            if (findSrccidList.Count != 0)
            {
                continue;
            }
            else
            {
                OSrccItem osrccItem = new OSrccItem();
                osrccItem.SrccId = srccId;
                osrccItem.OwnerName = ownername;
                value += "{\"id\":\"" + srccId + "\",\"OwnerName\":\"" + ownername + "\"},";
                srccIdList.Add(osrccItem);
            }
        }
        DataTable dtRow = dtShopList.Clone();
        DataTable dtShopCopy = dtShopList.Copy();
        for (int IntI = 0; IntI < dtShopCopy.Rows.Count; IntI++)
        {
            dtRow.Clear();
            dtRow.Rows.Add(dtShopCopy.Rows[IntI].ItemArray);
            child = JavaScriptConvert.SerializeObject(dtRow);
            child = child.Substring(child.IndexOf("{") + 1);
            child = child.Remove(child.LastIndexOf("]"));
            value += "{\"id\":\"" + IntI + "\", \"_parentId\":\"" + dtShopList.Rows[IntI]["SrccId"] + "\"," + child + ", ";
        }
        value = value.Remove(value.LastIndexOf(","));
        TxtJson = "{\"total\":" + page.totalRecord + ",\"rows\":[" + value + "]}";
    }
    #endregion

    #region 得到车位欠费列表
    /// <summary>
    /// 得到车位欠费列表
    /// </summary>
    public void GetCarPortDebtList()
    {
        Hashtable hash = new Hashtable();

        int pagesize = Convert.ToInt32(ParamsData["page"]);
        int rows = Convert.ToInt32(ParamsData["rows"]);
        hash.Add("carareacode", ParamsData["CarAreaCode"]);
        hash.Add("carcode", ParamsData["CarCode"]);

        PageInfo page = new PageInfo(rows, pagesize);

        AbstractGenericModel model = NewObject<AbstractGenericModel>("debt");
        DataTable dttCarPortList = (DataTable)model.OperationDataModel("GetCarPortDebtList", hash, page);
        string value = "";
        string child = "";
        List<OSrccItem> srccIdList = new List<OSrccItem>();
        for (int IntI = 0; IntI < dttCarPortList.Rows.Count; IntI++)
        {
            string srccId = dttCarPortList.Rows[IntI]["SrccId"].ToString();
            string ownername = dttCarPortList.Rows[IntI]["OwnerName"].ToString();
            List<OSrccItem> findSrccidList = srccIdList.FindAll(x => x.SrccId == srccId);
            if (findSrccidList.Count != 0)
            {
                continue;
            }
            else
            {
                OSrccItem osrccItem = new OSrccItem();
                osrccItem.SrccId = srccId;
                osrccItem.OwnerName = ownername;
                value += "{\"id\":\"" + srccId + "\",\"OwnerName\":\"" + ownername + "\"},";
                srccIdList.Add(osrccItem);
            }
        }
        DataTable dtRow = dttCarPortList.Clone();
        DataTable dtCarCopy = dttCarPortList.Copy();
        for (int IntI = 0; IntI < dtCarCopy.Rows.Count; IntI++)
        {
            dtRow.Clear();
            dtRow.Rows.Add(dtCarCopy.Rows[IntI].ItemArray);
            child = JavaScriptConvert.SerializeObject(dtRow);
            child = child.Substring(child.IndexOf("{") + 1);
            child = child.Remove(child.LastIndexOf("]"));
            value += "{\"id\":\"" + IntI + "\", \"_parentId\":\"" + dttCarPortList.Rows[IntI]["SrccId"] + "\"," + child + ", ";
        }
        value = value.Remove(value.LastIndexOf(","));
        TxtJson = "{\"total\":" + page.totalRecord + ",\"rows\":[" + value + "]}";
    }
    #endregion

    #region 得到客户欠费列表
    /// <summary>
    /// 得到客户欠费列表
    /// </summary>
    public void GetClientDebtList()
    {
        Hashtable hash = new Hashtable();

        int pagesize = Convert.ToInt32(ParamsData["page"]);
        int rows = Convert.ToInt32(ParamsData["rows"]);
        hash.Add("clientname", ParamsData["ClientName"]);

        PageInfo page = new PageInfo(rows, pagesize);

        AbstractGenericModel model = NewObject<AbstractGenericModel>("debt");
        DataTable dtClientList = (DataTable)model.OperationDataModel("GetClientDebtList", hash, page);

        string value = "";
        string child = "";
        List<OSrccItem> srccIdList = new List<OSrccItem>();
        for (int IntI = 0; IntI < dtClientList.Rows.Count; IntI++)
        {
            string srccId = dtClientList.Rows[IntI]["SrccId"].ToString();
            string ownername = dtClientList.Rows[IntI]["OwnerName"].ToString();
            List<OSrccItem> findSrccidList = srccIdList.FindAll(x => x.SrccId == srccId);
            if (findSrccidList.Count != 0)
            {
                continue;
            }
            else
            {
                OSrccItem osrccItem = new OSrccItem();
                osrccItem.SrccId = srccId;
                osrccItem.OwnerName = ownername;
                value += "{\"id\":\"" + srccId + "\",\"OwnerName\":\"" + ownername + "\"},";
                srccIdList.Add(osrccItem);
            }
        }
        DataTable dtRow = dtClientList.Clone();
        DataTable dtClientCopy = dtClientList.Copy();
        for (int IntI = 0; IntI < dtClientCopy.Rows.Count; IntI++)
        {
            dtRow.Clear();
            dtRow.Rows.Add(dtClientCopy.Rows[IntI].ItemArray);
            child = JavaScriptConvert.SerializeObject(dtRow);
            child = child.Substring(child.IndexOf("{") + 1);
            child = child.Remove(child.LastIndexOf("]"));
            value += "{\"id\":\"" + IntI + "\", \"_parentId\":\"" + dtClientList.Rows[IntI]["SrccId"] + "\"," + child + ", ";
        }
        value = value.Remove(value.LastIndexOf(","));
        TxtJson = "{\"total\":" + page.totalRecord + ",\"rows\":[" + value + "]}";
    }
    #endregion

    /// <summary>
    /// 打印
    /// </summary>
    public void GetDebtData()
    {

        Hashtable hash = new Hashtable();

        int pagesize =1;
        int rows =20;
        hash.Add("areacode", "");
        hash.Add("buildingCode", "");
        hash.Add("roomname", "");

        PageInfo page = new PageInfo(rows, pagesize);

        AbstractGenericModel model = NewObject<AbstractGenericModel>("debt");
        DataTable dtHomeList = (DataTable)model.OperationDataModel("GetHomeDebtList", hash, page);//住宅欠费数据

        PutOutData.Add("ReportPath", "Report\\DebtDataReport.rdlc");
        //System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
        //dic.Add("name", "kakake");
        //Session["ReportParameter"] = dic;
        DataSet ds = new DataSet();
        dtHomeList.TableName = "DebtData";
        ds.Tables.Add(dtHomeList.Copy());
        PutOutData.Add("ReportDataSource", ds);

        TxtJson = ReturnSuccess("");
    }


    //表头
    public class OSrccItem
    {
        public OSrccItem()
        { }
        public string SrccId { get; set; }
        public string OwnerName { get; set; }
    }
}
 
